package com.gimi.cloud.bbp.manage.controller.prod;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.enums.ServiceNameConstants;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.prod.EcProdCatModelValueDTO;
import com.gimi.cloud.bbp.manage.service.prod.EcProdCatModelService;
import com.gimi.cloud.bbp.manage.service.prod.EcProdCatModelValueService;
import com.github.pagehelper.PageInfo;

/**
 * 品类模板Controller
 * @auther loongs
 * @date 2017/12/18  16:21
 */
@RestController
@RequestMapping(value = "prodCatModelValue")
public class ProdCatModelValueController {
    private static Logger logger = LoggerFactory.getLogger(ProdCatModelValueController.class);
    private EcProdCatModelService prodCatModelService;
    private EcProdCatModelValueService prodCatModelValueService;
    @Autowired
    public ProdCatModelValueController(EcProdCatModelService prodCatModelService, EcProdCatModelValueService prodCatModelValueService) {
        this.prodCatModelService = prodCatModelService;
        this.prodCatModelValueService=prodCatModelValueService;
    }

    @RequestMapping(value = "/getProdCatModelValueList")
    public Response getProdCatModelValueList(@RequestBody EcProdCatModelValueDTO prodCatModelValueDTO, HttpServletResponse response) throws  Exception {
        logger.info("获得指定品类模板的所有属性值，入参："+prodCatModelValueDTO);
        Response resp = new Response();
        List<EcProdCatModelValueDTO> prodCatModelVaues = prodCatModelValueService.queryList(prodCatModelValueDTO,true);
        Map<String,Object> resData = new HashMap<String,Object>();
        resData.put(ServiceNameConstants.PAGEDATA_KEY,new PageInfo<>(prodCatModelVaues));
        resp.setRes_data(resData);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        return resp;
    }

    /* @RequestMapping(value = "/addProdCatModelValue")
    public Response addProdCatModelValue(@RequestBody EcProdCatModelValueDTO prodCatModelValueDTO, HttpServletResponse response) {
        logger.info("添加指定品类模板属性值，入参："+prodCatModelValueDTO);
        Response resp = new Response();
        boolean result= prodCatModelValueService.addProdCatModelValue(prodCatModelValueDTO);
        if(result){
            resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        }else{
            resp.setResponseCode(ResponseCodeEnum.PRODCATMODEL_VALUE_ADD_FAIL);
        }
        return resp;
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping(value = "/gotoEditProdCatModelValue")
    public Response gotoEditProdCatModelValue(@RequestBody EcProdCatModelValueDTO prodCatModelValueDTO, HttpServletResponse response) {
        logger.info("转跳到商品品类模板属性值编辑界面，入参："+prodCatModelValueDTO);
        Response resp = new Response();
        EcProdCatModelValueEntity prodCatModelValueEntity =prodCatModelValueService.gotoEditProdCatModelValue(prodCatModelValueDTO);
        resp.setRes_data(prodCatModelValueEntity);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
         return resp;
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp),response);
    }

    @RequestMapping(value = "/editProdCatModelValue")
    public Response editProdCatModelValue(@RequestBody EcProdCatModelValueDTO prodCatModelValueDTO, HttpServletResponse response) {
        logger.info("编辑（修改）商品品类模板属性值，入参："+prodCatModelValueDTO);
        Response resp = new Response();
        boolean result=prodCatModelValueService.editProdCatModelValue(prodCatModelValueDTO);
        if(result){
            resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        }else{
            resp.setResponseCode(ResponseCodeEnum.PRODCATMODEL_VALUE_EDIT_FAIL);
        }
         return resp;
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }


    @RequestMapping(value = "/realDeleteProdCatModelValue")
    public Response realDeleteProdCatModelValue(@RequestBody EcProdCatModelValueDTO prodCatModelValueDTO, HttpServletResponse response) {
        logger.info("删除商品品类模板属性值，入参："+prodCatModelValueDTO);
        Response resp = new Response();
        boolean result=prodCatModelValueService.realDeleteProdCatModelValue(prodCatModelValueDTO);
        if(result){
            resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        }else{
             resp.setResponseCode(ResponseCodeEnum.PRODCATID_REAL_DELETE_FAIL);
        }
         return resp;
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }*/
}
